﻿using AutoMapper;
using Ideaa.Data.Models;
using Ideaa.Data.Models.Base;
using Ideaa.Data.Models;
using Ideaa.Web.Models;
using System;
using System.Linq;
using Ideaa.Core.Extensions;

namespace Ideaa.Web.Mappings
{
    public class ViewModelToDomainMappingProfile : Profile
    {
        public override string ProfileName
        {
            get { return "ViewModelToDomainMappings"; }
        }

        protected override void Configure()
        {
            CreateMap<BaseEntityModel, BaseEntity>()
                .Include<PostEntityModel, PostEntity>()
                .Include<VoteModel, Vote>()
                .IgnoreAllVirtual()
                .ForMember(dest => dest.DateCreatedOnUtc, opt => opt.Ignore())
                .ForMember(dest => dest.Id, opt => opt.Ignore());

            CreateMap<PostEntityModel, PostEntity>()
                .Include<IdeaModel, Idea>()
                .Include<SuggestionModel, Suggestion>()
                .IgnoreAllVirtual();

            CreateMap<IdeaModel, Idea>()
                //.InheritMappingFromBaseType()
                .IgnoreAllVirtual();

            CreateMap<SuggestionModel, Suggestion>()
                //.InheritMappingFromBaseType()
                .IgnoreAllVirtual();
        }
    }
}
